﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.UpdateServices.Administration;

namespace WsusWebAdmin.Web.Controllers
{
    public class HomeController : UpdateServerBaseController
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {            
            return View();
        }

        public ActionResult UpdatesStatus()
        {
            ViewData.Model = UpdateServer.GetStatus();

            return PartialView("UpdatesStatus");
        }

        public ActionResult ComputersStatus()
        {
            var model = new Dictionary<IComputerTargetGroup, IUpdateSummary>();

            foreach (IComputerTargetGroup group in UpdateServer.GetComputerTargetGroups())
            {
                model[group] = group.GetTotalSummary();
            }

            ViewData.Model = model;

            return View();
        }

        public ActionResult DownloadStatus()
        {
            var progress = UpdateServer.GetContentDownloadProgress();

            ViewData.Model = progress;
            return View();
        }

        public ActionResult SynchronizationStatus()
        {
            var subscription = UpdateServer.GetSubscription();
            ViewData.Model = subscription.GetLastSynchronizationInfo();
            return View();            
        }
    }
}
